<?php

class Control_AboutController extends Zend_Controller_Action {

    public function init() {
        $this->_helper->layout->setLayout('admin');
        $this->yesButton = 'Yes'; //напис на кнопці Так під час видалення
        $this->noButton = 'No'; //напис на кнопці Ні під час видалення
        $this->aboutDb = new Control_Model_Table_About();
        $this->view->controller = $this->getRequest()->getControllerName();
        $this->view->action = $this->getRequest()->getActionName();
    }

    public function indexAction() {
        $this->_helper->redirector('edit');
    }

    public function addAction() {
        $form = new Control_Model_Form_About();
        $form->submit->setLabel('Add');
        $this->view->form = $form;
        $form->populate($formData);
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $name = $form->getValue('name');
                $text = $form->getValue('text');
                $this->servScrollDb->addServices($name, $text);
                $this->_helper->redirector('edit');
            } else {
                $form->populate($formData);
            }
        }
    }

    public function editAction() {
        $this->view->PortfolioData = $this->aboutDb->getAll();
        $form = new Control_Model_Form_About();
        $form->submit->setLabel('Update');
        $this->view->form = $form;
        $delparam = $this->_getParam('del', 0);

        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $title = $form->getValue('title');
                $text = $form->getValue('text');
                $this->aboutDb->updateServices($title, $text);
                $this->_helper->redirector('edit');
            }
        } else {//Виведення сторінки едіт
            $aboutData = $this->aboutDb->getDataID('1');
//            Zend_Debug::dump($aboutData);exit();
            $form->populate($aboutData);
        }
    }

}